<template>
	<view class="setup-wrapper">
		<div class="wrapper">
			<view class="bigbox" @click="navigateTo('/pages/mine/set/securityCenter/safe','login')">
				<image src="/static/icon-password.png" class="image" mode="aspectFit"></image>
				<div class="submit">支付密码</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/distribution/auth','auth')">
				<image src="/static/icon-authentication.png" class="image" mode="aspectFit"></image>
				<div class="submit">实名认证</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/invoiceManage/invoiceManage')">
				<image src="/static/icon-invoice.png" class="image" mode="aspectFit"></image>
				<div class="submit">发票管理</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/bankCard/bankCard')">
				<image src="/static/icon-bankcard.png" class="image" mode="aspectFit"></image>
				<div class="submit">银行卡管理</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/help/tips?type=privacy')">
				<image src="/static/icon-agreement.png" class="image" mode="aspectFit"></image>
				<div class="submit">隐私协议</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/help/tips?type=logout')">
				<image src="/static/icon-cancellation.png" class="image" mode="aspectFit"></image>
				<div class="submit">注销协议</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" @click="navigateTo('/pages/mine/set/aboutPlatform','login')">
				<image src="/static/icon-about.png" class="image" mode="aspectFit"></image>
				<div class="submit">关于平台</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox" v-if='(userInfo.partnerType=="1" || userInfo.partnerType=="2" || userInfo.partnerType=="4") 
						&& !userInfo.haveStore' @click="navigateTo('/pages/mine/set/logout','cancellation')">
				<image src="/static/icon-partner.png" class="image" mode="aspectFit"></image>
				<div class="submit">注销合伙人</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
			<view class="bigbox none" @click="showModalDialog">
				<image src="/static/icon-signout.png" class="image" mode="aspectFit"></image>
				<div class="submit">{{userInfo.id ?'退出登录':'返回登录'}}</div>
				<u-icon class="icon" name="arrow-right" size="28" color="#bbbbbb"></u-icon>
			</view>
		</div>
		<u-modal show-cancel-button v-model="quitShow" @confirm="confirm" :confirm-color="lightColor"
			:async-close="true" :content="userInfo.id ? '确定要退出登录么？' : '确定要返回登录么？'"></u-modal>
	</view>
</template>

<script>
	import {
		getUserInfo,
		SubmittedCancellation
	} from "@/api/members.js";
	import {
		logout
	} from "@/api/login";
	import storage from "@/utils/storage.js";
	import config from "@/config/config";
	export default {
		data() {
			return {
				config,
				lightColor: this.$lightColor,
				quitShow: false,
				isCertificate: false,
				userInfo: {},
				fileSizeString: "0B",
				content: ''
			};
		},
		onLoad(option) {
			this.type = option.type
		},
		onShow() {
			this.userInfo = this.$options.filters.isLogin();
		},
		methods: {
			navigateTo(url, type) {
				if (url == "/pages/set/securityCenter/securityCenter") {
					url += `?mobile=${this.userInfo.mobile}`;
				}
				if (type == 'login') {
					if (this.$options.filters.isLogin("auth")) {
						uni.navigateTo({
							url: url,
						});
					} else {
						this.$options.filters.forceLogin()
					}
				} else if (type === 'auth') {
					this.userInfo = storage.getUserInfo()
					if (this.userInfo.idCardNumber && this.userInfo.realName) {
						uni.showToast({
							title: '已认证',
							icon: 'none'
						})
						return
					} else {
						uni.navigateTo({
							url: url,
						});
					}
				} else if (type == "cancellation") {
					SubmittedCancellation().then((res) => {
						if (res.data.success) {
							if (res.data.result) {
								uni.navigateTo({
									url: './schedule'
								})
							} else {
								uni.navigateTo({
									url: './logout'
								})
							}
						} else {

						}
					})
				} else {
					uni.navigateTo({
						url: url,
					});
				}

			},
			clear() {
				this.$options.filters.clearAllStorage()
				this.$options.filters.navigateToLogin("redirectTo");
			},

			/**
			 * 确认退出
			 * 清除缓存重新登录
			 */
			async confirm() {
				await logout();
				this.clear();
			},

			/**
			 * 显示退出登录对话框
			 */
			showModalDialog() {
				this.quitShow = true;
			},
			/**
			 * 点击用户详情
			 * 判断当前是否进入用户中心
			 */
			checkUserInfo() {
				if (this.$options.filters.isLogin("auth")) {
					this.navigateTo("/pages/mine/set/personMsg");
				} else {
					this.$options.filters.navigateToLogin()
				}
			},
		},
	};
</script>

<style lang='scss' scoped>
	.setup-wrapper {
		padding: 24upx;

		.wrapper {
			background-color: #ffffff;
			border-radius: 16upx;
			overflow: hidden;
			box-shadow: 0px 6upx 12upx rgba(0, 0, 0, 0.05);

			.bigbox {
				height: 110rpx;
				display: flex;
				align-items: center;
				border-bottom: 2upx solid #eeeeee;

				.image {
					margin: 0 24upx;
					width: 40upx;
					height: 40upx;
				}

				.submit {
					flex: 1;
				}

				.icon {
					margin: 0 24upx;
				}
			}

			.none {
				border: none;
			}
		}
	}
</style>
